import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {ChatView} from './chat-view/chat-view';
import {Storage} from '@ionic/storage';
import {httpService} from "../../service/httpService";
import {HOST_URL} from "../../service/Constants";

/**
 *消息列表
 */
@IonicPage()
@Component({
  selector: 'page-news',
  templateUrl: 'news.html',
})

export class News {
  token;
  user;
  chatList;
  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              public storage: Storage,
              private http: httpService,) {

    this.storage.get("token").then(data => {
      this.token = data;
    });
    //用户信息
    this.storage.get("userInfo").then(data => {
      this.user = data;
      this.getChatList();
    });
  }

  ionViewDidLoad() {
  }

  //获取消息列表
  getChatList() {
    this.http.get(HOST_URL + '/api/v1/chat_list/?filter=', {idUser: this.user.id},this.token ).then(res => {
      if (res.error.code == '0') {
        this.chatList=res.rows;
      } else if (res.error.code == '801') {

      }
    })
  }
  toChatView(item){
    this.navCtrl.push(ChatView, {item: item});
  }
}
